package com.kaizige.realtor.Dao;

import com.kaizige.realtor.Pojo.record;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class recordDao {
	@Autowired
	JdbcTemplate jt;
	
	// 获取所有看房记录
	public List<Map<String,Object>> getAllRecord(){
		String sql = "select * from record";
		List<Map<String, Object>> maps = jt.queryForList(sql);
		return maps;
	}
	
	// 按名字获取看房记录
	public List<Map<String,Object>> getHisRecordByName(String name){
		String sql = "select * from record where tenant=? and record_status=1";
		List<Map<String, Object>> maps = jt.queryForList(sql, name);
		return maps;
	}
	public List<Map<String,Object>> getNowRecordByName(String name){
		String sql = "select * from record where tenant=? and record_status=0";
		List<Map<String, Object>> maps = jt.queryForList(sql, name);
		return maps;
	}
	public List<Map<String,Object>> getRecordByName(String name){
		String sql = "select * from record where tenant=?";
		List<Map<String, Object>> maps = jt.queryForList(sql, name);
		return maps;
	}
	
	// 添加一条记录
	public void addRecord(record r){
		String sql = "insert into record values(?,?,?,?,?)";
		Object[] args = {r.getId(),r.getTenant(),r.getHouse_id(),
				r.getRecord_date(),r.getRecord_status()};
		jt.update(sql,args);
	}
	
	// 修改记录状态
	public void upRecSta(int id){
		String sql = "update record set record_status=1 where id=?";
		jt.update(sql,id);
	}
	
	// 删除一条记录
	public void delRec(int id){
		String sql = "delete from record where id=?";
		jt.update(sql,id);
	}
}
